#include <iostream>

using namespace std;

int main() {
    int num;
    cin >> num;
    char data[num][2];
    int result[3][2]={0,0,0,0,0,0};

    for (int i = 0; i < num; i++) {
        cin >> data[i][0] >> data[i][1];
    }

    for (int i = 0; i < num; ++i) {
        if ((data[i][0] == 'B') && (data[i][1] == 'C')) {
            result[0][0]++;
        }
        if ((data[i][0] == 'B') && (data[i][1] == 'J')) {
            result[2][1]++;
        }
        if ((data[i][0] == 'C') && (data[i][1] == 'B')) {
            result[0][1]++;
        }
        if ((data[i][0] == 'C') && (data[i][1] == 'J')) {
            result[1][0]++;
        }
        if ((data[i][0] == 'J') && (data[i][1] == 'B')) {
            result[2][0]++;
        }
        if ((data[i][0] == 'J') && (data[i][1] == 'C')) {
            result[1][1]++;
        }
    }

    int win = result[0][0] + result[1][0] + result[2][0];
    int lose = result[0][1] + result[1][1] + result[2][1];
    int same = num - win - lose;

    cout << win << " " << same << " " << lose << endl;
    cout << lose << " " << same << " " << win << endl;

    int indexj = -1;
    int maxj = -1;
    int indexy = -1;
    int maxy = -1;

    for (int i = 0; i < 3; i++) {
        if (result[i][0] > maxj) {
            maxj = result[i][0];
            indexj = i;
        }
        if (result[i][1] > maxy) {
            maxy = result[i][1];
            indexy = i;
        }
    }

    char chj;
    char chy;

    if (indexj == 0) {
        chj = 'B';
    } else if (indexj == 1) {
        chj = 'C';
    } else {
        chj = 'J';
    }

    if (indexy == 0) {
        chy = 'B';
    } else if (indexy == 1) {
        chy = 'C';
    } else {
        chy = 'J';
    }

    cout << chj << " " << chy << endl;

    return 0;
}

